{% extends "base.html" %}
{% load static %}

{% block title %}首页 | MyBlog{% endblock %}

{% block content %}
<div class="container mt-5">
    <!-- 欢迎横幅 -->
    <div class="jumbotron bg-light p-5 rounded-lg mb-4">
        <h1 class="display-4">欢迎来到 MyBlog!</h1>
        <p class="lead">这是一个基于 Django 构建的个人博客系统，分享技术、生活和思考。</p>
        <hr class="my-4">
        <p>探索最新的文章，了解最新的技术趋势，或分享你的想法。</p>
        <a class="btn btn-primary btn-lg" href="#featured-posts" role="button">阅读最新文章</a>
        {% if not user.is_authenticated %}
        <a class="btn btn-outline-primary btn-lg ms-2" href="{% url 'users:register' %}" role="button">立即注册</a>
        {% endif %}
    </div>

    <!-- 特色文章区域 -->
    <div id="featured-posts" class="mb-5">
        <h2 class="mb-4 border-bottom pb-2">精选文章</h2>
        <div class="row">
            <!-- 文章卡片 1 -->
            <div class="col-md-6 mb-4">
                <div class="card h-100 shadow-sm">
                    <img src="https://images.unsplash.com/photo-1499750310107-5fef28a66643?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=800&q=80"
                         class="card-img-top" alt="Django框架" style="height: 200px; object-fit: cover;">
                    <div class="card-body">
                        <span class="badge bg-primary mb-2">技术</span>
                        <h5 class="card-title">深入理解Django ORM工作原理</h5>
                        <p class="card-text">Django ORM是Django框架的核心组件之一，它提供了一种高效、Pythonic的数据库访问方式...</p>
                        <div class="d-flex justify-content-between align-items-center mt-3">
                            <a href="#" class="btn btn-sm btn-outline-primary">阅读更多</a>
                            <small class="text-muted">2023-08-15</small>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 文章卡片 2 -->
            <div class="col-md-6 mb-4">
                <div class="card h-100 shadow-sm">
                    <img src="https://images.unsplash.com/photo-1555066931-4365d14bab8c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=800&q=80"
                         class="card-img-top" alt="Python编程" style="height: 200px; object-fit: cover;">
                    <div class="card-body">
                        <span class="badge bg-success mb-2">编程</span>
                        <h5 class="card-title">Python异步编程最佳实践</h5>
                        <p class="card-text">随着Python对异步编程支持的不断完善，asyncio已经成为高性能Python应用的基石...</p>
                        <div class="d-flex justify-content-between align-items-center mt-3">
                            <a href="#" class="btn btn-sm btn-outline-primary">阅读更多</a>
                            <small class="text-muted">2023-08-10</small>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 最新文章区域 -->
    <div class="mb-5">
        <h2 class="mb-4 border-bottom pb-2">最新文章</h2>
        <div class="row">
            <!-- 文章列表 -->
            {% for post in posts %}
            <div class="col-lg-4 col-md-6 mb-4">
                <div class="card h-100">
                    {% if post.featured_image %}
                    <img src="{{ post.featured_image.url }}" class="card-img-top" alt="{{ post.title }}" style="height: 160px; object-fit: cover;">
                    {% else %}
                    <div class="bg-secondary text-light d-flex align-items-center justify-content-center" style="height: 160px;">
                        <i class="fas fa-image fa-3x"></i>
                    </div>
                    {% endif %}
                    <div class="card-body">
                        <span class="badge bg-info mb-2">{{ post.category.name }}</span>
                        <h5 class="card-title">{{ post.title }}</h5>
                        <p class="card-text">{{ post.content|truncatechars:100|striptags }}</p>
                    </div>
                    <div class="card-footer bg-white border-0">
                        <div class="d-flex justify-content-between align-items-center">
                            <a href="{% url 'blog:post_detail' post.id %}" class="btn btn-sm btn-outline-primary">阅读全文</a>
                            <small class="text-muted">
                                <i class="fas fa-eye me-1"></i> {{ post.views }}
                                <i class="fas fa-comment ms-2 me-1"></i> 12
                            </small>
                        </div>
                    </div>
                </div>
            </div>
            {% empty %}
            <div class="col-12">
                <div class="alert alert-info text-center">
                    暂无文章发布
                </div>
            </div>
            {% endfor %}
        </div>

        <!-- 分页控件 -->
        <nav aria-label="文章分页">
            <ul class="pagination justify-content-center">
                <li class="page-item disabled">
                    <a class="page-link" href="#" tabindex="-1" aria-disabled="true">上一页</a>
                </li>
                <li class="page-item active"><a class="page-link" href="#">1</a></li>
                <li class="page-item"><a class="page-link" href="#">2</a></li>
                <li class="page-item"><a class="page-link" href="#">3</a></li>
                <li class="page-item">
                    <a class="page-link" href="#">下一页</a>
                </li>
            </ul>
        </nav>
    </div>

    <!-- 分类和标签区域 -->
    <div class="row">
        <div class="col-md-6 mb-4">
            <div class="card shadow-sm">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">文章分类</h5>
                </div>
                <div class="list-group list-group-flush">
                    {% for category in categories %}
                    <a href="{% url 'blog:category_posts' category.slug %}" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                        {{ category.name }}
                        <span class="badge bg-primary rounded-pill">{{ category.post_set.count }}</span>
                    </a>
                    {% endfor %}
                </div>
            </div>
        </div>

        <div class="col-md-6 mb-4">
            <div class="card shadow-sm">
                <div class="card-header bg-success text-white">
                    <h5 class="mb-0">热门标签</h5>
                </div>
                <div class="card-body">
                    <div class="tag-cloud">
                        {% for tag in popular_tags %}
                        <a href="{% url 'blog:tag_posts' tag.slug %}" class="badge bg-light text-dark me-1 mb-2">
                            <i class="fas fa-tag me-1"></i> {{ tag.name }}
                        </a>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_css %}
<style>
    .jumbotron {
        background: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
        color: white;
        border-radius: 10px;
    }

    .card {
        transition: transform 0.3s, box-shadow 0.3s;
        border-radius: 8px;
        overflow: hidden;
        border: none;
    }

    .card:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 20px rgba(0,0,0,0.1);
    }

    .tag-cloud a {
        display: inline-block;
        padding: 5px 15px;
        background: #eef1f7;
        border-radius: 30px;
        margin: 0 5px 10px 0;
        color: #4e73df;
        text-decoration: none;
        transition: all 0.3s;
    }

    .tag-cloud a:hover {
        background: #4e73df;
        color: white;
    }

    .card-header {
        border-radius: 8px 8px 0 0 !important;
    }
</style>
{% endblock %}